package me.jollyfly.jshop.content.server.controller

import me.jollyfly.jshop.common.bean.ResultBean
import me.jollyfly.jshop.content.client.api.ContentApi
import me.jollyfly.jshop.content.client.model.ContentDO
import me.jollyfly.jshop.content.server.dao.ContentDAO
import me.jollyfly.jshop.content.server.service.ContentService
import me.jollyfly.jshop.framework.aop.LogRecord
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController

/**
 * 内容管理微服务
 *
 * @author jollyfly
 */
@RestController
open class ContentController @Autowired
constructor(private val contentDAO: ContentDAO) : ContentApi {




    @Autowired
    private var contentService:ContentService? = null

    /**
     * 根据内容分类id获取该分类下所有的内容
     *
     * @param catId 内容分类Id
     *
     * @return ResultBean
     *
     * @author jollyfly
     */

    @LogRecord("根据内容分类id获取该分类下所有的内容")
    override fun listContentByCat(@PathVariable("id") catId: Long?): ResultBean<List<ContentDO>> {
        val list = this.contentDAO.listContentByCat(catId)
        return ResultBean(list)
    }

    /**
     * 根据内容code获取所有内容
     *
     * @param code 内容编号code
     *
     * @return
     */
    @LogRecord("根据内容code获取所有内容")
    override fun listContentByCode(@PathVariable("code") code: String): ResultBean<List<ContentDO>> {
        val list = this.contentDAO.listContentByCode(code)
        return ResultBean(list)
    }


    override fun listSliders(): ResultBean<List<ContentDO>> {
        val sliders = this.contentService!!.listSliders()
        return ResultBean(sliders)
    }

    override fun listRecommendation(): ResultBean<List<ContentDO>> {
        val recommendationList = this.contentService!!.listRecommendation()
        return ResultBean(recommendationList)
    }

}
